# -*- coding: utf-8 -*-

import string
import numpy as np
import pandas as pd


# 读取文件
# 写入文件

def excel():
    """excel文件"""
    excel_path = r''
    df: pd.DataFrame = pd.read_excel(excel_path)
    df.to_excel(excel_path)

    # df写入指定sheet
    excel_writer = pd.ExcelWriter(excel_path)
    df1 = pd.DataFrame()
    df1.to_excel(excel_writer, sheet_name='Sheet1')
    df2 = pd.DataFrame()
    df2.to_excel(excel_writer, sheet_name='Sheet2')


    pass


def csv():
    """csv文件"""
    pd.read_csv()

    pass


def stata():
    # 读取dta文件
    pd.read_stata()

    pass


def json():
    n = 10
    df = pd.DataFrame(data=np.arange(0, n * n, 1).reshape(n, n),
                      index=list(string.ascii_lowercase[:n]),
                      columns=list(string.ascii_uppercase[:n]))
    # Series转json，默认的orient是'index'，orient可选参数有 {'split','records','index','table'}
    # DataFrame转json，默认的orient是'columns'，
    # orient可选参数有 {'split','records','index','table','columns','values'}

    # split -> {"index":[index_,...],"columns":[column_,...],"data":[value_,...]}
    # records -> [{column_:value_},...]
    # index -> {index_:{column_:value_,...},...}
    # columns -> {column_:{index_:value_,...},...}
    # values -> [[value_,...],...]
    # table -> {"schema":{"fields":[{"name":column_,"type":type_},...],
    #           "data":[{"index":index_,column_:value_,...},...]}

    # json_str = df.to_json(orient='split')
    json_str = df.to_json(orient='records')
    # json_str = df.to_json(orient='index')
    # json_str = df.to_json(orient='columns')
    # json_str = df.to_json(orient='values')
    # json_str = df.to_json(orient='table')

    print(json_str)

    df1 = pd.read_json(json_str, orient='records')
    print(df1)
    pass


def sql():
    # 读取数据库

    pd.read_sql()
    pd.read_sql_query()
    pd.read_sql_table()

    pass


if __name__ == '__main__':
    json()
    pass
